/**
 * Created by lyl on 2015/3/11.
 */

(function(){

    $(document).ready(function(){

        var targets = $('section').height($(window).height());

        $(document).scroll(function(){

            var self = this;

            $.each(targets,function(index,ele){

                if($(self).scrollTop() > $(ele).offset().top - 20
                    && $(self).scrollTop() < $(ele).height() + $(ele).offset().top + 20){

                    $(ele).find('h1').addClass('bigger').end().siblings('section').find('h1').removeClass('bigger');
                    $('a').removeClass('active');
                    $('nav a[href=#' + $(ele).attr('id') + ']').addClass('active').end();

                    console.log($(ele).attr('id'));

                }

            });

        });

    });

})();
